<input type="button" class="btnPrint" value="Print" onclick="javascript:window.print();" />
<!--<input type="button" class="btnPrint" value="PDF" onclick="javascript:alert('');" />-->
<?php
foreach ($ids as $id) {
    $medalID = 0;
    $issues = $this->db->query("
                SELECT 
                        Medal_Stock_Issue.issue_number,
                        Medal_Stock_Issue.issue_for,
                        Medal_Stock_Issue.`date`,
                        Medal_Stock_Issue.organization,
                        Official_Order.Order_Number
                        FROM Medal_Stock_Issue
                        INNER JOIN Medalissue_order ON Medalissue_order.medal_stock_issue_ID = Medal_Stock_Issue.ID
                        RIGHT JOIN Official_Order ON Official_Order.ID = Medalissue_order.official_order_ID
                        WHERE Medal_Stock_Issue.ID='$id' ORDER BY Medal_Stock_Issue.ID
                ")->result_array();


    $medal = $this->db->query("
            SELECT Medal_Stock_Issue_Amount.Medal_Stock_Issue_ID, Medal.Medal_Class_ID, Medal.Medal_Type_ID, Medal_Stock_Issue_Amount.amount FROM Medal_Stock_Issue_Amount
                RIGHT JOIN Medal ON Medal.ID = Medal_Stock_Issue_Amount.Medal_ID
                AND Medal_Stock_Issue_Amount.Medal_Stock_Issue_ID = '$id' ORDER BY Medal_Stock_Issue_Amount.Medal_Stock_Issue_ID, Medal.ID ASC")->result_array();
//    if ($currentIssue == $cissue["issue_number"]){
//        continue;
//    }
//    $currentIssue = $cissue["issue_number"];
    ?>
    <div style="text-align: center">
        <?php echo "<img align='absmiddle' src='" . $root . "public/images/pdf/new_issue_title.png'  />"; ?>
    </div>
    <div>
        <div><?php echo "<img align='absmiddle' src='" . $root . "public/images/pdf/ministry.png'  />"; ?></div>
        <div><?php echo "<img align='absmiddle' src='" . $root . "public/images/pdf/ministry_level.png'  />"; ?></div>
    </div>
    <div style="height: 10px"></div>
    <div>
        <div><?php echo "<img align='absmiddle' src='" . $root . "public/images/pdf/number.png'  />"; ?>: <?php echo $issues[0]['issue_number']; ?></div>
    </div>
    <div style="height: 10px"></div>
    <div>
        <div><?php echo "<img align='absmiddle' src='" . $root . "public/images/pdf/to.png'  />"; ?>: <?php echo $issues[0]['issue_for']; ?></div>
        <div><?php echo "<img align='absmiddle' src='" . $root . "public/images/pdf/officer.png'  />"; ?>: <?php echo $issues[0]['organization']; ?></div>
        <div><?php echo "<img align='absmiddle' src='" . $root . "public/images/pdf/reference.png'  />"; ?>:
            <?php
            foreach ($issues as $issue) {
                echo $issue["Order_Number"] . "; ";
            }
            ?>
        </div>
    </div>
<!--    <div style="height: 10px"></div>-->
    <div>    
        <div><?php echo "<img align='absmiddle' src='" . $root . "public/images/pdf/medal5level.png'  />"; ?></div>
    </div>
    <div style="height: 10px"></div>
    <div>
        <table class="table" cellpadding="0" border="1" cellspacing="0">
            <tr>
                <td rowspan="2" class="left top bottom"><?php echo "<img align='absmiddle' src='" . $root . "public/images/pdf/no.png'  />"; ?></td>
                <td rowspan="2"  class="left top bottom"><?php echo "<img align='absmiddle' src='" . $root . "public/images/pdf/type.png'  />"; ?></td>
                <td colspan="5" class="left top bottom"><?php echo "<img align='absmiddle' src='" . $root . "public/images/pdf/qty.png'  />"; ?></td>
                <td colspan="3" class="left top bottom"><?php echo "<img align='absmiddle' src='" . $root . "public/images/pdf/box.png'  />"; ?></td>
                <td rowspan="2" class="left right top bottom"><?php echo "<img align='absmiddle' src='" . $root . "public/images/pdf/niyabat.png'  />"; ?></td>
            </tr>
            <tr>
                <td class="left bottom"><?php echo "<img align='absmiddle' src='" . $root . "public/images/pdf/mhasereyvot.png'  />"; ?></td>
                <td class="left bottom"><?php echo "<img align='absmiddle' src='" . $root . "public/images/pdf/mhasena.png'  />"; ?></td>
                <td class="left bottom"><?php echo "<img align='absmiddle' src='" . $root . "public/images/pdf/thipadin.png'  />"; ?></td>
                <td class="left bottom"><?php echo "<img align='absmiddle' src='" . $root . "public/images/pdf/sena.png'  />"; ?></td>
                <td class="left bottom"><?php echo "<img align='absmiddle' src='" . $root . "public/images/pdf/asharith.png'  />"; ?></td>
                <td class="left bottom"><?php echo "<img align='absmiddle' src='" . $root . "public/images/pdf/big.png'  />"; ?></td>
                <td class="left bottom"><?php echo "<img align='absmiddle' src='" . $root . "public/images/pdf/medium.png'  />"; ?></td>
                <td class="left bottom"><?php echo "<img align='absmiddle' src='" . $root . "public/images/pdf/small.png'  />"; ?></td>
            </tr>
            <tr>
                <td class="left bottom no"><?php echo "១"; ?></td>
                <td class="left bottom type"><?php echo "<img align='absmiddle' src='" . $root . "public/images/pdf/cambodia.png'  />"; ?></td>
                <td class="left bottom"><?php echo number_format($medal[0]['amount']); ?></td>
                <td class="left bottom"><?php
        echo number_format($medal[$medalID++]['amount']);
        ;
            ?></td>
                <td class="left bottom"><?php
                echo number_format($medal[$medalID++]['amount']);
                ;
            ?></td>
                <td class="left bottom"><?php
                echo number_format($medal[$medalID++]['amount']);
                ;
            ?></td>
                <td class="left bottom"><?php
                echo number_format($medal[$medalID++]['amount']);
                ;
            ?></td>
                <td class="left bottom size"><?php echo ""; ?></td>
                <td class="left bottom size"><?php echo ""; ?></td>
                <td class="left bottom size"><?php echo ""; ?></td>
                <td class="left bottom right"><?php echo ""; ?></td>
            </tr>
            <tr>
                <td class="left bottom no"><?php echo "២"; ?></td>
                <td class="left bottom type"><?php echo "<img align='absmiddle' src='" . $root . "public/images/pdf/queen.png'  />"; ?></td>
                <td class="left bottom"><?php echo number_format($medal[$medalID++]['amount']); ?></td>
                <td class="left bottom"><?php
                echo number_format($medal[$medalID++]['amount']);
                ;
            ?></td>
                <td class="left bottom"><?php
                echo number_format($medal[$medalID++]['amount']);
                ;
            ?></td>
                <td class="left bottom"><?php
                echo number_format($medal[$medalID++]['amount']);
                ;
            ?></td>
                <td class="left bottom"><?php
                echo number_format($medal[$medalID++]['amount']);
                ;
            ?></td>
                <td class="left bottom size"><?php echo ""; ?></td>
                <td class="left bottom size"><?php echo ""; ?></td>
                <td class="left bottom size"><?php echo ""; ?></td>
                <td class="left bottom right"><?php echo ""; ?></td>
            </tr>
            <tr>
                <td class="left bottom no"><?php echo "៣"; ?></td>
                <td class="left bottom type"><?php echo "<img align='absmiddle' src='" . $root . "public/images/pdf/sovanthara.png'  />"; ?></td>
                <td class="left bottom"><?php echo number_format($medal[$medalID++]['amount']); ?></td>
                <td class="left bottom"><?php
                echo number_format($medal[$medalID++]['amount']);
                ;
            ?></td>
                <td class="left bottom"><?php
                echo number_format($medal[$medalID++]['amount']);
                ;
            ?></td>
                <td class="left bottom"><?php
                echo number_format($medal[$medalID++]['amount']);
                ;
            ?></td>
                <td class="left bottom"><?php
                echo number_format($medal[$medalID++]['amount']);
                ;
            ?></td>
                <td class="left bottom size"><?php echo ""; ?></td>
                <td class="left bottom size"><?php echo ""; ?></td>
                <td class="left bottom size"><?php echo ""; ?></td>
                <td class="left bottom right"><?php echo ""; ?></td>
            </tr>
            <tr>
                <td class="left bottom no"><?php echo "៤"; ?></td>
                <td class="left bottom type"><?php echo "<img align='absmiddle' src='" . $root . "public/images/pdf/munisaraphon.png'  />"; ?></td>
                <td class="left bottom"><?php echo number_format($medal[$medalID++]['amount']); ?></td>
                <td class="left bottom"><?php
                echo number_format($medal[$medalID++]['amount']);
                ;
            ?></td>
                <td class="left bottom"><?php
                echo number_format($medal[$medalID++]['amount']);
                ;
            ?></td>
                <td class="left bottom"><?php
                echo number_format($medal[$medalID++]['amount']);
                ;
            ?></td>
                <td class="left bottom"><?php
                echo number_format($medal[$medalID++]['amount']);
                ;
            ?></td>
                <td class="left bottom size"><?php echo ""; ?></td>
                <td class="left bottom size"><?php echo ""; ?></td>
                <td class="left bottom size"><?php echo ""; ?></td>
                <td class="left bottom right"><?php echo ""; ?></td>
            </tr>
            <tr>
                <td class="left bottom no"><?php echo "៥"; ?></td>
                <td class="left bottom type"><?php echo "<img align='absmiddle' src='" . $root . "public/images/pdf/sahametrey.png'  />"; ?></td>
                <td class="left bottom"><?php echo number_format($medal[$medalID++]['amount']); ?></td>
                <td class="left bottom"><?php
                echo number_format($medal[$medalID++]['amount']);
                ;
            ?></td>
                <td class="left bottom"><?php
                echo number_format($medal[$medalID++]['amount']);
                ;
            ?></td>
                <td class="left bottom"><?php
                echo number_format($medal[$medalID++]['amount']);
                ;
            ?></td>
                <td class="left bottom"><?php
                echo number_format($medal[$medalID++]['amount']);
                ;
            ?></td>
                <td class="left bottom size"><?php echo ""; ?></td>
                <td class="left bottom size"><?php echo ""; ?></td>
                <td class="left bottom size"><?php echo ""; ?></td>
                <td class="left bottom right"><?php echo ""; ?></td>
            </tr>
        </table>
    </div>
<!--    <div style="height: 10px"></div>-->
    <div>    
        <div><?php echo "<img align='absmiddle' src='" . $root . "public/images/pdf/medal3level.png'  />"; ?></div>
    </div>
    <div style="height: 10px"></div>
    <div>
        <table class="table" cellpadding="0" border="1" cellspacing="0">
            <tr>
                <td rowspan="2" class="left top bottom"><?php echo "<img align='absmiddle' src='" . $root . "public/images/pdf/no.png'  />"; ?></td>
                <td rowspan="2"  class="left top bottom"><?php echo "<img align='absmiddle' src='" . $root . "public/images/pdf/type.png'  />"; ?></td>
                <td colspan="3" class="left top bottom"><?php echo "<img align='absmiddle' src='" . $root . "public/images/pdf/qty.png'  />"; ?></td>
                <td rowspan="2" class="left top bottom"><?php echo "<img align='absmiddle' src='" . $root . "public/images/pdf/box.png'  />"; ?></td>
                <td rowspan="2" class="left right top bottom"><?php echo "<img align='absmiddle' src='" . $root . "public/images/pdf/niyabat.png'  />"; ?></td>
            </tr>
            <tr>
                <td class="left bottom"><?php echo "<img align='absmiddle' src='" . $root . "public/images/pdf/gold.png'  />"; ?></td>
                <td class="left bottom"><?php echo "<img align='absmiddle' src='" . $root . "public/images/pdf/silver.png'  />"; ?></td>
                <td class="left bottom"><?php echo "<img align='absmiddle' src='" . $root . "public/images/pdf/platium.png'  />"; ?></td>
            </tr>   
            <tr>
                <td class="left bottom no"><?php echo "១"; ?></td>
                <td class="left bottom type"><?php echo "<img align='absmiddle' src='" . $root . "public/images/pdf/protect.png'  />"; ?></td>
                <td class="left bottom"><?php echo number_format($medal[$medalID++]['amount']); ?></td>
                <td class="left bottom"><?php
                echo number_format($medal[$medalID++]['amount']);
                ;
            ?></td>
                <td class="left bottom"><?php
                echo number_format($medal[$medalID++]['amount']);
                ;
            ?></td>
                <td class="left bottom"><?php echo ""; ?></td>
                <td class="left bottom right"><?php echo ""; ?></td>
            </tr>
            <tr>
                <td class="left bottom no"><?php echo "២"; ?></td>
                <td class="left bottom type"><?php echo "<img align='absmiddle' src='" . $root . "public/images/pdf/job.png'  />"; ?></td>
                <td class="left bottom"><?php echo number_format($medal[$medalID++]['amount']); ?></td>
                <td class="left bottom"><?php
                echo number_format($medal[$medalID++]['amount']);
                ;
            ?></td>
                <td class="left bottom"><?php
                echo number_format($medal[$medalID++]['amount']);
                ;
            ?></td>
                <td class="left bottom"><?php echo ""; ?></td>
                <td class="left bottom right"><?php echo ""; ?></td>
            </tr>
            <tr>
                <td class="left bottom no"><?php echo "៣"; ?></td>
                <td class="left bottom type"><?php echo "<img align='absmiddle' src='" . $root . "public/images/pdf/build.png'  />"; ?></td>
                <td class="left bottom"><?php echo number_format($medal[$medalID++]['amount']); ?></td>
                <td class="left bottom"><?php
                echo number_format($medal[$medalID++]['amount']);
                ;
            ?></td>
                <td class="left bottom"><?php
                echo number_format($medal[$medalID++]['amount']);
                ;
            ?></td>
                <td class="left bottom"><?php echo ""; ?></td>
                <td class="left bottom right"><?php echo ""; ?></td>
            </tr>
            <tr>
                <td class="left bottom no"><?php echo "៤"; ?></td>
                <td class="left bottom type"><?php echo "<img align='absmiddle' src='" . $root . "public/images/pdf/woman.png'  />"; ?></td>
                <td class="left bottom"><?php echo number_format($medal[$medalID++]['amount']); ?></td>
                <td class="left bottom"><?php
                echo number_format($medal[$medalID++]['amount']);
                ;
            ?></td>
                <td class="left bottom"><?php
                echo number_format($medal[$medalID++]['amount']);
                ;
            ?></td>
                <td class="left bottom"><?php echo ""; ?></td>
                <td class="left bottom right"><?php echo ""; ?></td>
            </tr>
            <tr>
                <td class="left bottom no"><?php echo "៥"; ?></td>
                <td class="left bottom type"><?php echo "<img align='absmiddle' src='" . $root . "public/images/pdf/khmersport.png'  />"; ?></td>
                <td class="left bottom"><?php echo number_format($medal[$medalID++]['amount']); ?></td>
                <td class="left bottom"><?php
                echo number_format($medal[$medalID++]['amount']);
                ;
            ?></td>
                <td class="left bottom"><?php
                echo number_format($medal[$medalID++]['amount']);
                ;
            ?></td>
                <td class="left bottom"><?php echo ""; ?></td>
                <td class="left bottom right"><?php echo ""; ?></td>
            </tr>
        </table>
    </div>
<!--    <div style="height: 10px"></div>-->
    <div>    
        <div><?php echo "<img align='absmiddle' src='" . $root . "public/images/pdf/medal1level.png'  />"; ?></div>
    </div>
    <div style="height: 10px"></div>
    <div>
        <table class="table" cellpadding="0" border="1" cellspacing="0">
            <tr>
                <td class="left top bottom"><?php echo "<img align='absmiddle' src='" . $root . "public/images/pdf/no.png'  />"; ?></td>
                <td  class="left top bottom"><?php echo "<img align='absmiddle' src='" . $root . "public/images/pdf/type.png'  />"; ?></td>
                <td class="left top bottom"><?php echo "<img align='absmiddle' src='" . $root . "public/images/pdf/qty.png'  />"; ?></td>
                <td class="left top bottom"><?php echo "<img align='absmiddle' src='" . $root . "public/images/pdf/box.png'  />"; ?></td>
                <td class="left right top bottom"><?php echo "<img align='absmiddle' src='" . $root . "public/images/pdf/niyabat.png'  />"; ?></td>
            </tr>
            <tr>
                <td class="left bottom no"><?php echo "១"; ?></td>
                <td class="left bottom type"><?php echo "<img align='absmiddle' src='" . $root . "public/images/pdf/cheatobkar.png'  />"; ?></td>
                <td class="left bottom"><?php echo number_format($medal[$medalID++]['amount']); ?></td>
                <td class="left bottom"><?php echo ""; ?></td>
                <td class="left bottom right"><?php echo ""; ?></td>
            </tr>
            <tr>
                <td class="left bottom no"><?php echo "២"; ?></td>
                <td class="left bottom type"><?php echo "<img align='absmiddle' src='" . $root . "public/images/pdf/independent.png'  />"; ?></td>
                <td class="left bottom"><?php echo number_format($medal[$medalID++]['amount']); ?></td>
                <td class="left bottom"><?php echo ""; ?></td>
                <td class="left bottom right"><?php echo ""; ?></td>
            </tr>
            <tr>
                <td class="left bottom no"><?php echo "៣"; ?></td>
                <td class="left bottom type"><?php echo "<img align='absmiddle' src='" . $root . "public/images/pdf/senacheysith.png'  />"; ?></td>
                <td class="left bottom"><?php echo number_format($medal[$medalID++]['amount']); ?></td>
                <td class="left bottom"><?php echo ""; ?></td>
                <td class="left bottom right"><?php echo ""; ?></td>
            </tr>
        </table>
    </div>
    <div style="height: 10px"></div>
    <div style="float:right;">
        បញ្ចេញនៅថ្ងៃទី <?php echo date("d", strtotime($issue['date'])); ?> ខែ <?php echo date("m", strtotime($issue['date'])); ?> ឆ្នាំ <?php echo date("Y", strtotime($issue['date'])); ?>
    </div>
    <div style="height: 10px"></div>
    <div>
        <table class="table">
            <tr>
                <td>ប្រធាននាយកដ្ឋាន</td>
                <td>អ្នកទទួល</td>
                <td>ឆ្មាំឃ្លាំង</td>
            </tr>
        </table>
    </div>
<?php } ?>